Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify usage of WatchSet methods and behaviour of First/Last #118

Merged
merged 2 commits into from
Jan 31, 2022

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Jan 28, 2022

The behaviour of First/Last methods can be verified using the following simple test:

type Job struct {
	ID string
}

func TestRepro(t *testing.T) {
	dbSchema := &memdb.DBSchema{
		Tables: map[string]*memdb.TableSchema{
			"jobs": {
				Name: "jobs",
				Indexes: map[string]*memdb.IndexSchema{
					"id": {
						Name:    "id",
						Unique:  true,
						Indexer: &memdb.StringFieldIndex{Field: "ID"},
					},
				},
			},
		},
	}

	db, err := memdb.NewMemDB(dbSchema)
	if err != nil {
		t.Fatal(err)
	}

	txn0 := db.Txn(false)

	txn1 := db.Txn(true)
	t.Cleanup(txn1.Abort)
	err = txn1.Insert("jobs", &Job{
		ID: "one",
	})
	if err != nil {
		t.Fatal(err)
	}
	txn1.Commit()

	obj, err := txn0.First("jobs", "id")
	if err != nil {
		t.Fatal(err)
	}
	t.Logf("received obj = %#v", obj)
}
go test ./internal/scheduler -run=TestRepro -v -count=1
=== RUN   TestRepro
    scheduler_test.go:59: received obj = <nil>
--- PASS: TestRepro (0.00s)
PASS
ok  	github.com/hashicorp/terraform-ls/internal/scheduler	0.315s

@radeksimko radeksimko force-pushed the clarify-usage branch 2 times, most recently from d477e45 to 4b8ad53 Compare January 28, 2022 18:44
txn.go Outdated Show resolved Hide resolved
Copy link
Member

@banks banks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for improving this Radek!

@radeksimko radeksimko merged commit 0176005 into master Jan 31, 2022
@radeksimko radeksimko deleted the clarify-usage branch January 31, 2022 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants